package com.woniuxy.carrental.controller;

import com.woniuxy.carrental.entity.Complaint;
import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.service.ComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * controller调用
 * 查询投诉信息，添加或删除
 */

@RestController
public class ComplaintController {

    @Autowired
    ComplaintService complaintService;



    //分页查询投诉信息
    @GetMapping("/selectComplaints")
    public ResponseResult<PageBean<Complaint>> getComplaint(Complaint complaint, int pageIndex, int pageSize){


        PageBean<Complaint> pageBean= new PageBean<>();

        try {
            //获取客户合同的总条数
            int i = complaintService.selectComplaintCount();

            //获取全部合同客户数据
            List<Complaint> complaints = complaintService.selectComplaintByPage(pageIndex, pageSize, complaint);

            pageBean = new PageBean<>();
            pageBean.setBeanList(complaints);
            pageBean.setPageIndex(pageIndex);
            pageBean.setPageSize(pageSize);
            pageBean.setTotalRecord(i);

            return new ResponseResult<PageBean<Complaint>>(pageBean,200,"查询完成");
        } catch (Exception e) {

            return new ResponseResult<PageBean<Complaint>>(pageBean,404,"查询失败");
        }

    }
    /*
    处理投诉信息
     */
    @PutMapping("/updateComplaint/{complaintId}")
    public ResponseResult updateComplaint(@PathVariable("complaintId")Integer complaintId){

        complaintService.updateComplaint(complaintId);

        return new ResponseResult<PageBean<Complaint>>(null,200,"处理成功");
    }

}
